//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.moons.settings.config;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

class ARUtil {
    private static final char[] hexArray = "0123456789ABCDEF".toCharArray();

    ARUtil() {
    }

    static void int2bytes(byte[] barray, int offset, int a) {
        if (barray != null && barray.length >= 4) {
            long lv = (long)a;
            barray[offset + 3] = (byte)((int)(lv >> 24 & 255L));
            barray[offset + 2] = (byte)((int)(lv >> 16 & 255L));
            barray[offset + 1] = (byte)((int)(lv >> 8 & 255L));
            barray[offset] = (byte)((int)(lv & 255L));
        }
    }

    static int bytes2int(byte[] barray, int offset) {
        int ret = 0;

        for(int i = 3; i >= 0 && i + offset < barray.length; --i) {
            ret <<= 8;
            ret |= barray[offset + i] & 255;
        }

        return ret;
    }

    public static float bytes2float(byte[] barray, int offset) {
        float ret = ByteBuffer.wrap(Arrays.copyOfRange(barray, offset, offset + 4)).order(ByteOrder.LITTLE_ENDIAN).getFloat();
        return ret;
    }

    static void short2bytes(byte[] barray, int offset, int a) {
        if (barray != null && barray.length >= 2) {
            barray[offset + 1] = (byte)(a >> 8 & 255);
            barray[offset] = (byte)(a & 255);
        }
    }

    static short bytes2short(byte[] barray, int offset) {
        short ret = 0;
        ret = (short)(ret | barray[offset + 1] & 255);
        ret = (short)(ret << 8);
        ret = (short)(ret | barray[offset] & 255);
        return ret;
    }

    public static void long2bytes(byte[] barray, int offset, long a) {
        if (barray != null && barray.length >= 8) {
            barray[offset + 7] = (byte)((int)(a >> 56 & 255L));
            barray[offset + 6] = (byte)((int)(a >> 48 & 255L));
            barray[offset + 5] = (byte)((int)(a >> 40 & 255L));
            barray[offset + 4] = (byte)((int)(a >> 32 & 255L));
            barray[offset + 3] = (byte)((int)(a >> 24 & 255L));
            barray[offset + 2] = (byte)((int)(a >> 16 & 255L));
            barray[offset + 1] = (byte)((int)(a >> 8 & 255L));
            barray[offset] = (byte)((int)(a & 255L));
        }
    }

    public static long intbytes2long(byte[] barray, int offset) {
        long ret = 0L;

        for(int i = 3; i >= 0 && i + offset < barray.length; --i) {
            ret <<= 8;
            ret |= (long)barray[offset + i] & 255L;
        }

        return ret;
    }

    public static int intbytes2int(byte[] barray, int offset) {
        int ret = 0;

        for(int i = 3; i >= 0 && i + offset < barray.length; --i) {
            ret <<= 8;
            ret |= barray[offset + i] & 255;
        }

        return ret;
    }

    public static long longbytes2long(byte[] barray, int offset) {
        long ret = 0L;

        for(int i = 7; i >= 0 && i + offset < barray.length; --i) {
            ret <<= 8;
            ret |= (long)barray[offset + i] & 255L;
        }

        return ret;
    }

    public static long checkSum2long(byte[] data, int psize, int poff) {
        long a = 0L;

        for(int i = 0; i < psize; ++i) {
            a += (long)(data[poff + i] & 255);
        }

        return a;
    }

    static void checkSum(byte[] data, int psize, int poff, int coff) {
        long lcs = 0L;

        for(int i = 0; i < psize; ++i) {
            lcs += (long)data[poff + i];
        }

        data[coff + 3] = (byte)((int)(lcs >> 24 & 255L));
        data[coff + 2] = (byte)((int)(lcs >> 16 & 255L));
        data[coff + 1] = (byte)((int)(lcs >> 8 & 255L));
        data[coff] = (byte)((int)(lcs & 255L));
    }

    static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];

        for(int j = 0; j < bytes.length; ++j) {
            int v = bytes[j] & 255;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 15];
        }

        return new String(hexChars);
    }
}
